package web;

import gerenciador.Empresa;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import conexao.ConnectionPool;
import dao.EmpresaDAOBD;

@WebServlet(urlPatterns="/novaEmpresabd")
public class NovaEmpresaBD extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		String nome = req.getParameter("nome");
		
		try( Connection con = new ConnectionPool().getConnection() ){
			Empresa empresa = new Empresa(nome);
			new EmpresaDAOBD(con).adiciona(empresa);
			
			PrintWriter writer = resp.getWriter();
			
			writer.println("<html><body>");
			writer.println("<br>Empresa adicionada com sucesso: "+ empresa.getNome() + "<br/>");
			writer.println("</body></html>");

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
